-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ENH: implement at
#53
Conversation
376ad49
to
4a0943a
Compare
Rebased on top of #58 |
|
Any idea how to fix this? Looks like the ubuntu_latest VM has an obsolete driver (or more likely no driver)
|
I don't think we can get GPU CI without paying someone for it, cc @rgommers . |
Can cupy run on a CPU-only host? |
Yep, that's on my radar to push forward this month, on multiple projects. Please feel free to open a new issue and assign it to me. I think we can hook up a shared GPU runner between this project and
I don't think so. |
@lucascolley ready for merge and release! 🥳 |
good to proceed @rgommers ? |
looks great, thanks! Note to self: we ought to add
to |
Annoyingly, codecov is glitching (again). It's stating in the "Files" view of this PR that the tests never run under JAX, but if you follow the link from the log of Check ci-backends it says that everything's green. |
yeah, happy to just ignore that, but also happy if anyone figures out how to fix that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @crusaderky and reviewers. This is looking quite good. A couple of comments (disclaimer: it's a little hard to dig through the already-resolved review comments, so I may be saying something that was already discussed there):
(1) The copy=True
default seems wrong to me. The main point of this feature is that we can replace in-place operations like x[idx, :] += y
in SciPy et al. with something new to support JAX. That something new should be the idiomatic JAX way, so x = xpx.at(x)[idx, :].add(y)
. This should come with as little of a performance penalty for NumPy usage as possible - hence the copy=True
default doesn't work. It's already a significant concession to code readability to have to avoid +=
& co, and having to also add copy=None
in all places where performance matters seems too much.
(2) When playing around with this branch, most things work as expected, but this was a little surprising:
>>> x = np.arange(5)
>>> x = xpx.at(x)[[3, 4]].divide(1.5)
>>> x.dtype
dtype('int64')
>>> x = np.arange(5)
>>> x /= 1.5
Traceback (most recent call last):
Cell In[32], line 1
x /= 1.5
UFuncTypeError: Cannot cast ufunc 'divide' output from dtype('float64') to dtype('int64') with casting rule 'same_kind'
Is this on purpose or by accident? Raising on these cases may be cleaner if that can be done in a performant way.
(3) Library support is pretty comprehensive already; a few others come to mind. MLX is already supported by the generic path since it allows in-place syntax (I think, didn't verify). It also has array.at which matches JAX syntax/semantics. ndonnx
is going to need explicit support in the future as well, since it's immutable like JAX, but that can be left for later since it doesn't seem to have Array.at
or another alternative here. tl;dr nothing to change in this PR I think.
Allow for the alternate syntax ``at(x)[start:stop:step]``. | ||
|
||
It looks prettier than ``at(x, slice(start, stop, step))`` | ||
and feels more intuitive coming from the JAX documentation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be the default way of doing things in the examples? Best to steer people to what feels idiomatic to JAX users I'd think. I'd de-emphasize, or perhaps even leave out completely (if there are no downsides to that), the alternative syntax.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been writing several prototype PRs on various submodules of Sphinx.
From the experience I gathered there, I must say that at(x)[idx]
feels more natural and easier on the eyes when there are multiple indices and/or slices, whereas at(x, idx)
feels nicer and less cluttered in all other cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, fair enough - seems like an argument to keep both then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact, I've been considered writing aliases for the benefit of readability set_at(x, idx, value)
etc. but haven't gone for them for the sake of keeping the API surface small.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not adding a third way sounds like a healthy idea at least for now - let's see how we like this in its current form I'd say.
Changed it to copy=None
TIL that
are almost always equivalent! Fixed. |
shall we get going with a release? :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks ready to me now, +1 for merge & release if everyone else is happy too.
let's give this a whirl, thanks all! if you can point the SciPy PR to the release when it is out @crusaderky, I can update the sklearn PR |
Implement a new
at(x, idx)
orat(x)[idx]
function, mocking the syntax of JAX's omonymous method .This is propaedeutic to JAX support in libraries that support the Array API, e.g. scipy.
Moved from data-apis/array-api-compat#205
Blockers
Blocks
_lib
: JAX support (non-jitted) scipy/scipy#22070